# 自定义过滤器,实现新闻颜色提示
from functools import wraps

from flask import session, g


def do_index_class_filter(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return "second"
    elif index == 3:
        return "third"
    else:
        return ""

#判断用户登陆装饰器
def user_login_data(view_func):
    @wraps(view_func)
    def wrapper(*args, **kwargs):
        # 获取到用户编号
        user_id = session.get('user_id')

        # 查询用户对象
        user = None
        if user_id:
            from info.models import User
            user = User.query.get(user_id)
        # 将用户对象设置到g对象中
        g.user = user
        return view_func(*args, **kwargs)
    return wrapper